package com.lggry.demo6collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionTraversalDemo3 {
    public static void main(String[] args) {
        //目标：掌握Collection集合的遍历方式一：迭代器遍历
        Collection<String> names = new ArrayList<>();
        names.add("小明");
        names.add("小红");
        names.add("小刚");
        names.add("小花");
        System.out.println(names);

        //1.得到这个集合的迭代器对象
        Iterator<String> it = names.iterator();
        String rs = it.next();

        //2.使用一个while循环来遍历
        while (it.hasNext()) {
            String name = it.next();
            System.out.println(name);
        }
    }
}
